<template>
	<view class="settle">
		<u-toast ref="uToast"></u-toast>
		<view class="settle__tip">修改类型选择</view>
		<u-cell-group>
			<u-cell-item title="收益配置" :arrow="true" value="查看详情" bg-color="white" @click="goCost()">

			</u-cell-item>
			<u-cell-item title="交易分润代付开关" :arrow="false" bg-color="white">
				<u-switch slot="right-icon" v-model="tradeBenefitCheck" @change="changeProfitSwitch"></u-switch>
			</u-cell-item>
			<u-cell-item title="笔数代付开关" :arrow="false" bg-color="white">
				<u-switch slot="right-icon" v-model="numBenefitCheck" @change="changeSettleSwitch()"></u-switch>
			</u-cell-item>
			<u-cell-item title="返现配置" :arrow="true" value="查看详情" bg-color="white" @click="goReturn()">

			</u-cell-item>
			<u-cell-item title="返现代付开关" :arrow="false" bg-color="white">
				<u-switch slot="right-icon" v-model="returnCheck" @change="changeCashbackSwitch()"></u-switch>
			</u-cell-item>
		</u-cell-group>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				customStyle: {
					// 注意驼峰命名，并且值必须用引号包括，因为这是对象
					backgroundColor: '#9D60FF'
				},
				tradeBenefitCheck: true,
				numBenefitCheck: true,
				returnCheck: true,

				agentNo: "",
				agentInfoDo: {},
				settleInfoDo: {},
				agentActivityInfoVos: [],
				agentPolicyCostInfo: [],

			}
		},

		onLoad(options) {
			this.agentNo = options.agentNo;
			this.queryAgentHasCostConfig();
			this.getAgentDetail();

		},
		methods: {

			changeProfitSwitch() {
				const _that = this;
				let status = _that.tradeBenefitCheck ? "1" : "0";
				_that.$zx.user_api.profitSwitch(_that.agentNo, status).then((data) => {
					console.log("data=" + JSON.stringify(data))
					this.$refs.uToast.show({
						title: '修改成功',

					})

				});

			},
			changeSettleSwitch() {
				const _that = this;
				let status = _that.numBenefitCheck ? "1" : "0";
				_that.$zx.user_api.settleProfitSwitch(_that.agentNo, status).then((data) => {
					console.log("data=" + JSON.stringify(data))
					this.$refs.uToast.show({
						title: '修改成功',

					})

				});

			},
			changeCashbackSwitch() {
				const _that = this;
				let status = _that.returnCheck ? "1" : "0";
				_that.$zx.user_api.cashbackSwitch(_that.agentNo, status).then((data) => {
					console.log("data=" + JSON.stringify(data))
					this.$refs.uToast.show({
						title: '修改成功',

					})

				});

			},
			queryAgentHasCostConfig() {
				const _that = this;
				_that.$zx.user_api.queryAgentHasCostConfig(_that.agentNo).then((data) => {
					// console.log("data=" + JSON.stringify(data))

					// _that.merchantRateInfoDo = data;
				});
			},
			getAgentDetail() {
				const _that = this;
				_that.$zx.user_api.getAgentDetail(_that.agentNo, "detail").then((data) => {
					// console.log("data=" + JSON.stringify(data))

					_that.agentInfoDo = data.agentInfoDo;
					_that.settleInfoDo = data.settleInfoDo;
					_that.agentActivityInfoVos = data.agentActivityInfoVos;
					_that.agentPolicyCostInfo = data.agentPolicyCostInfo;

					_that.tradeBenefitCheck = _that.agentInfoDo.profitSwitch == "1";
					_that.numBenefitCheck = _that.agentInfoDo.settleProfitSwitch == "1";
					_that.returnCheck = _that.agentInfoDo.cashbackSwitch == "1";

				});
			},
			goReturn() {

				this.$u.route({
					url: 'packageA/pages/main/agent/agentAddReappearanceAllocationMoney',
					params: {
						"agentPolicyCostInfo": encodeURIComponent(JSON.stringify(this.agentActivityInfoVos)),
						flag: "1",
						agentNo: this.agentNo
					}
				})
			},
			goCost() {

				this.$u.route({
					url: 'packageA/pages/main/agent/agentCostAllocationDetail',
					params: {
						"agentPolicyCostInfo": encodeURIComponent(JSON.stringify(this.agentPolicyCostInfo)),
						flag: "1",
						agentNo: this.agentNo
					}
				})
			},
		},
	}
</script>

<style scoped lang="scss">
	.settle {
		&__top {
			width: 100%;
		}

		&__tip {
			background-color: #f6f6f6;
			height: 70rpx;
			line-height: 70rpx;
			padding: 0 20rpx;
			font-size: 12px;
		}

		&__form {
			background-color: white;
		}

		&__upload {
			background-color: white;
			padding: 20rpx;
		}
	}

	.tip {
		text-align: center;
	}

	.slot-content {
		padding: 20rpx;
		font-size: 14px;
	}
</style>